<?php

/**
 * This is the model class for table "{{trip}}".
 *
 * The followings are the available columns in table '{{trip}}':
 * @property string $id
 * @property string $vessel_id
 * @property integer $gear_id
 * @property string $trip_type
 * @property integer $gsa
 * @property string $code
 * @property string $temporary_code
 * @property integer $sampling
 * @property string $date
 * @property string $year
 * @property integer $quarter
 * @property integer $month
 * @property string $harbor
 * @property string $trip_number
 * @property string $create_time
 * @property string $create_user_id
 * @property string $update_time
 * @property string $update_user_id
 *
 * The followings are the available model relations:
 * @property Haul[] $hauls
 * @property Gear $gear
 * @property Vessel $vessel
 * @property Sampler[] $tblSamplers
 * @property Yield[] $yields
 */
class Trip extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Trip the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{trip}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('vessel_id, gear_id, trip_type, code, temporary_code, sampling, date, year, quarter, month, harbor, trip_number, create_time, create_user_id, update_time, update_user_id', 'required'),
			array('gear_id, gsa, sampling, quarter, month', 'numerical', 'integerOnly'=>true),
			array('vessel_id, trip_number, create_user_id, update_user_id', 'length', 'max'=>10),
			array('trip_type', 'length', 'max'=>1),
			array('code', 'length', 'max'=>12),
			array('temporary_code', 'length', 'max'=>255),
			array('year', 'length', 'max'=>4),
			array('harbor', 'length', 'max'=>40),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, vessel_id, gear_id, trip_type, gsa, code, temporary_code, sampling, date, year, quarter, month, harbor, trip_number, create_time, create_user_id, update_time, update_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'hauls' => array(self::HAS_MANY, 'Haul', 'trip_id'),
			'gear' => array(self::BELONGS_TO, 'Gear', 'gear_id'),
			'vessel' => array(self::BELONGS_TO, 'Vessel', 'vessel_id'),
			'tblSamplers' => array(self::MANY_MANY, 'Sampler', '{{tripSampler}}(trip_id, sampler_id)'),
			'yields' => array(self::HAS_MANY, 'Yield', 'trip_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'vessel_id' => 'Vessel',
			'gear_id' => 'Gear',
			'trip_type' => 'Trip Type',
			'gsa' => 'Gsa',
			'code' => 'Code',
			'temporary_code' => 'Temporary Code',
			'sampling' => 'Sampling',
			'date' => 'Date',
			'year' => 'Year',
			'quarter' => 'Quarter',
			'month' => 'Month',
			'harbor' => 'Harbor',
			'trip_number' => 'Trip Number',
			'create_time' => 'Create Time',
			'create_user_id' => 'Create User',
			'update_time' => 'Update Time',
			'update_user_id' => 'Update User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('vessel_id',$this->vessel_id,true);
		$criteria->compare('gear_id',$this->gear_id);
		$criteria->compare('trip_type',$this->trip_type,true);
		$criteria->compare('gsa',$this->gsa);
		$criteria->compare('code',$this->code,true);
		$criteria->compare('temporary_code',$this->temporary_code,true);
		$criteria->compare('sampling',$this->sampling);
		$criteria->compare('date',$this->date,true);
		$criteria->compare('year',$this->year,true);
		$criteria->compare('quarter',$this->quarter);
		$criteria->compare('month',$this->month);
		$criteria->compare('harbor',$this->harbor,true);
		$criteria->compare('trip_number',$this->trip_number,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('create_user_id',$this->create_user_id,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user_id',$this->update_user_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}